package Game;

import javax.swing.*;
import java.awt.event.*;

public class Game implements Config {
    private Chessboard chessboard;
    private JButton btnStart, btnPause, btnRestart;
    private JFrame mainFrame;

    public Game() {
        btnStart = new JButton("开始");
        btnPause = new JButton("暂停");
        btnRestart = new JButton("重新开始");

        mainFrame = new JFrame();
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.setBounds(100, 50, 5 * SIZE + 2 * X0 + (COLUMNS - 1) * SIZE, 2 * Y0 + (ROWS - 1) * SIZE + 40);
        chessboard = new Chessboard();
        mainFrame.setContentPane(chessboard);
        mainFrame.setVisible(true);

        chessboard.add(btnStart);
        btnStart.setBounds(2 * X0 + (COLUMNS - 1) * SIZE + SIZE, Y0, 3 * SIZE, 2 * SIZE);
        ActionListener listenerStart = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                chessboard.setChessable(true);
            }
        };
        btnStart.addActionListener(listenerStart);

        chessboard.add(btnPause);
        btnPause.setBounds(2 * X0 + (COLUMNS - 1) * SIZE + SIZE, Y0 + (ROWS - 1) * SIZE / 2 - SIZE, 3 * SIZE, 2 * SIZE);
        ActionListener listenerPause = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                chessboard.setChessable(false);
            }
        };
        btnPause.addActionListener(listenerPause);

        chessboard.add(btnRestart);
        btnRestart.setBounds(2 * X0 + (COLUMNS - 1) * SIZE + SIZE, Y0 + (ROWS - 1) * SIZE - SIZE * 2, 3 * SIZE, 2 * SIZE);
        ActionListener listenerRestart = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                chessboard.restart();
                mainFrame.setContentPane(chessboard);
            }
        };
        btnRestart.addActionListener(listenerRestart);
    }

    public static void main(String[] args) {
        Game g = new Game();
    }
}